package com.nkdx.ws.mapper;

import com.nkdx.ws.dto.RegionDto;
import com.nkdx.ws.eto.RegionEto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 *  地域 Mapper
 * @author ZZW
 * @date 2022/3/2 10:08 下午
 * @param
 * @return
 */
@Repository
public interface RegionMapper {
    @Insert("insert into ws_region (`id`, `parent_id`,`type`, `name`, `code`, `desc`) VALUES (#{id}, #{parentId},#{type},#{name}, #{code}, #{desc});")
    public void insert(RegionEto eto);

    @Select("select `id`, `parent_id` as parentId,`type`, `name`, `code`, `desc` FROM ws_region WHERE type = #{type}")
    public List<RegionDto> findAllByType(String type);

    @Select("select `id`, `parent_id` as parentId,`type`, `name`, `code`, `desc` FROM ws_region WHERE type = #{type} AND name like CONCAT('%',#{name},'%') limit 1")
    public RegionDto findByLikeNameAndType(@Param("name") String name,@Param("type") String type);
}
